package com.bidepan.validation.two;

import jakarta.validation.ConstraintViolation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;

import java.util.List;
import java.util.Set;

@Service
public class Myvalidator2 {
    @Autowired
    private Validator validator;
    public boolean validatorByUsertwo(User user){
       BindException BindException = new BindException(user,user.getName());
       validator.validate(user, BindException);
       List< ObjectError > allErrors = BindException.getAllErrors();
       System.out.println("Error: " + allErrors);
       return BindException.hasErrors();
    };
}
